#include "Region.h"
//#include "windows.h"
#include <string.h>

CRegion::CRegion(void)
{
	SetRegion(0,0,0,0);
	m_handler = NULL;
}

CRegion::~CRegion(void)
{
	DeleteHandler();
}

CRegion::CRegion(CRegion const& cpy)
{
	m_x1=cpy.m_x1;
	m_x2=cpy.m_x2;
	m_y1=cpy.m_y1;
	m_y2=cpy.m_y2;

	if(cpy.m_handler!=NULL)
		m_handler = strdup(cpy.m_handler);
	else
		m_handler=NULL;
}

void CRegion::SetRegion( int x1,int y1, int x2, int y2 )
{
	m_x1=x1;
	m_x2=x2;
	m_y1=y1;
	m_y2=y2;
}

void CRegion::SetHandler( const char* handler )
{
	DeleteHandler();
	if(handler!=NULL)
	{
		m_handler = strdup(handler);
	}
}

bool CRegion::isEqual( char* operand )
{
	if(strcmp(m_handler,operand)==0)
		return true;
	else
		return false;
}

bool CRegion::isInside( int px,int py )
{
	if(px>m_x1 && px<m_x2 && py>m_y1 && py<m_y2)
		return true;
	else
		return false;
}

void CRegion::DeleteHandler()
{
	if(m_handler!=NULL)
		delete m_handler;
	m_handler = NULL;
}

char* CRegion::GetHandler()
{
	if(m_handler!=NULL)
		return strdup(m_handler);
	else
		return NULL;
}
